##
# ConMan Makefile
##

PROJECT=	conman

CC=		@CC@
CFLAGS=		@CFLAGS@
CPPFLAGS=	@CPPFLAGS@
DEBUG_CFLAGS=	@DEBUG_CFLAGS@
DEFAULT_INCS=	-I.
DEFS=		@DEFS@
INSTALL=	@INSTALL@
IPMI_LIBS=	@IPMI_LIBS@
IPMI_OBJS=	@IPMI_OBJS@
LDFLAGS=	@LDFLAGS@
LIBPTHREAD=	@LIBPTHREAD@
LIBS=		@LIBS@
RANLIB=		@RANLIB@
SHELL=		@SHELL@
@SET_MAKE@
COMPILE_OPTS=	$(DEFS) $(DEFAULT_INCS) $(CPPFLAGS) $(DEBUG_CFLAGS) $(CFLAGS)
COMPILE=	$(CC) $(COMPILE_OPTS)

top_srcdir=	@top_srcdir@
prefix=		@prefix@
exec_prefix=	@exec_prefix@
bindir=		@bindir@
sbindir=	@sbindir@
libdir=		@libdir@
mandir=		@mandir@
sysconfdir=	@sysconfdir@
datarootdir=	@datarootdir@

AC_OUTPUT=	Makefile config.h etc/conman.init \
		man/conman.1 man/conman.conf.5 man/conmand.8

PROGS=		conman conmand
COMMON_OBJS=	\
		common.o \
		list.o \
		lex.o \
		log.o \
		util.o \
		util-file.o \
		util-net.o \
		util-str.o \
		@LIBOBJS@
CLIENT_OBJS=	\
		client.o \
		client-conf.o \
		client-sock.o \
		client-tty.o \
		$(COMMON_OBJS)
SERVER_OBJS=	\
		server.o \
		server-conf.o \
		server-esc.o \
		server-logfile.o \
		server-obj.o \
		server-process.o \
		server-serial.o \
		server-sock.o \
		server-telnet.o \
		server-unixsock.o \
		$(IPMI_OBJS) \
		inevent.o \
		tpoll.o \
		$(COMMON_OBJS)
COMMON_LIBS=	$(LIBPTHREAD) $(LIBS)
CLIENT_LIBS=	$(COMMON_LIBS)
SERVER_LIBS=	$(COMMON_LIBS) $(IPMI_LIBS)

all: $(PROGS) tags

conman: $(CLIENT_OBJS)
	$(COMPILE) $(LDFLAGS) $(CLIENT_OBJS) $(CLIENT_LIBS) -o $@

conmand: $(SERVER_OBJS)
	$(COMPILE) $(LDFLAGS) $(SERVER_OBJS) $(SERVER_LIBS) -o $@

.c.o:
	$(COMPILE) -c $<

install: $(PROGS)
	$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
	$(INSTALL) -m 755 conman $(DESTDIR)$(bindir)/
	$(INSTALL) -m 755 conmen $(DESTDIR)$(bindir)/
	$(INSTALL) -m 755 -d $(DESTDIR)$(sbindir)
	$(INSTALL) -m 755 conmand $(DESTDIR)$(sbindir)/
	$(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir)
	@ test ! -f $(DESTDIR)$(sysconfdir)/conman.conf \
	    || cmp etc/conman.conf $(DESTDIR)$(sysconfdir)/conman.conf \
	    1>/dev/null 2>&1 || new=".new"; \
	  echo $(INSTALL) -m 600 etc/conman.conf \
	    $(DESTDIR)$(sysconfdir)/conman.conf$${new}; \
	  $(INSTALL) -m 600 etc/conman.conf \
	    $(DESTDIR)$(sysconfdir)/conman.conf$${new}
	$(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir)/init.d
	@ test ! -f $(DESTDIR)$(sysconfdir)/init.d/conman \
	    || cmp etc/conman.init $(DESTDIR)$(sysconfdir)/init.d/conman \
	    1>/dev/null 2>&1 || new=".new"; \
	  echo $(INSTALL) -m 755 etc/conman.init \
	    $(DESTDIR)$(sysconfdir)/init.d/conman$${new}; \
	  $(INSTALL) -m 755 etc/conman.init \
	    $(DESTDIR)$(sysconfdir)/init.d/conman$${new}
	$(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir)/logrotate.d
	@ test ! -f $(DESTDIR)$(sysconfdir)/logrotate.d/conman \
	    || cmp etc/conman.logrotate \
	    $(DESTDIR)$(sysconfdir)/logrotate.d/conman \
	    1>/dev/null 2>&1 || new=".new"; \
	  echo $(INSTALL) -m 644 etc/conman.logrotate \
	    $(DESTDIR)$(sysconfdir)/logrotate.d/conman$${new}; \
	  $(INSTALL) -m 644 etc/conman.logrotate \
	    $(DESTDIR)$(sysconfdir)/logrotate.d/conman$${new}
	@ test -d /etc/sysconfig && d=sysconfig || d=default; \
	  echo $(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir)/$$d; \
	  $(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir)/$$d; \
	  test ! -f $(DESTDIR)$(sysconfdir)/$$d/conman \
	    || cmp etc/conman.sysconfig $(DESTDIR)$(sysconfdir)/$$d/conman \
	    1>/dev/null 2>&1 || new=".new"; \
	  echo $(INSTALL) -m 644 etc/conman.sysconfig \
	    $(DESTDIR)$(sysconfdir)/$$d/conman$${new}; \
	  $(INSTALL) -m 644 etc/conman.sysconfig \
	    $(DESTDIR)$(sysconfdir)/$$d/conman$${new}
	@ for f in `cd lib >/dev/null \
	      && find * -name ".*" -prune -o -type f -print`; do \
	    expr "$$f" : ".*\.exp" && mode=755 || mode=644; \
	    echo $(INSTALL) -m 755 -d \
	      `dirname $(DESTDIR)$(prefix)/lib/$(PROJECT)/$$f`; \
	    $(INSTALL) -m 755 -d \
	      `dirname $(DESTDIR)$(prefix)/lib/$(PROJECT)/$$f`; \
	    echo $(INSTALL) -m $${mode} \
	      lib/$$f $(DESTDIR)$(prefix)/lib/$(PROJECT)/$$f; \
	    $(INSTALL) -m $${mode} lib/$$f \
	      $(DESTDIR)$(prefix)/lib/$(PROJECT)/$$f; \
	  done
	@ for d in man1 man5 man8; do \
	    echo $(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/$$d; \
	    $(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/$$d; \
	  done
	$(INSTALL) -m 644 man/conman.1 \
	  $(DESTDIR)$(mandir)/man1/conman.1
	$(INSTALL) -m 644 man/conman.conf.5 \
	  $(DESTDIR)$(mandir)/man5/conman.conf.5
	$(INSTALL) -m 644 man/conmand.8 \
	  $(DESTDIR)$(mandir)/man8/conmand.8

clean:
	-rm -f *.o *.a *~ \#* .\#* cscope*.out core core.* *.core tags TAGS

realclean: clean
	-rm -f $(PROGS)

distclean: realclean
	-rm -fr autom4te*.cache autoscan.*
	-rm -f config.cache config.log config.status stamp-h Makefile.bak
	-rm -f $(AC_OUTPUT)

depend:
	-makedepend -Y -- $(COMPILE_OPTS) -- *.[ch] 2>/dev/null

tags: *.[ch]
	-ctags *.[ch] 2>/dev/null


# AUTO-REMAKE OF AUTOCONF-RELATED TARGETS

Makefile: Makefile.in config.status
	./config.status

config.status: META
	./config.status --recheck


# DO NOT DELETE THIS LINE -- make depend depends on it.
